import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';

import { Service } from '../../../server/server';
import { CudTableService } from '../../../public/serve/cud-table/cud-table.service';
@Component({
  selector: 'app-management-search',
  templateUrl: './management-search.component.html'
})
export class ManagementSearchComponent implements OnInit {

  constructor(private server: Service, private tableListService: CudTableService, ) { }

  ngOnInit() {
    //搜索数据
    this.srarchData = {
      queryCriteria: '',
      startCreateTime: '',
      endCreateTime: '',
      startLoginTime: '',
      endLoginTime: '',
      queryType: 1,
      pageNumber: 1,
      pageSize: 20,
      id: ''
    }
  }

  public srarchData: any;
  //展开搜索
  public opensearch: boolean = false;
  public opensearchtitle: string = "展开搜索";
  openSearch() {
    this.opensearch = !this.opensearch;
    if (!this.opensearch) {
      this.opensearchtitle = "展开搜索";
    } else {
      this.opensearchtitle = "关闭搜索";
    }
    //发射搜索框状态
    this.server.perstatseventEmit.emit(this.opensearch)
  }

  //机构Id
  @Input() superiorId: any;

  @Output()
  searchOutput: EventEmitter<any> = new EventEmitter();

  //查询
  search() {
    let data = {
      queryCriteria: this.srarchData.queryCriteria,
      startCreateTime: this.server.formatDate(this.srarchData.startCreateTime),
      endCreateTime: this.server.formatDate(this.srarchData.endCreateTime),
      startLoginTime: this.server.formatDate(this.srarchData.startLoginTime),
      endLoginTime: this.server.formatDate(this.srarchData.endLoginTime),
      queryType: 1,
      pageNumber: 1,
      pageSize: 20,
      id: this.superiorId || '12aa1c87305f4271a90bffeb28315ca2'
      //|| '12aa1c87305f4271a90bffeb28315ca2'
    }
    //console.log(data)
    // let url = this.server.baseUrl + 'admin/pusers/getPusersList';
    // this.tableListService.postRequest(url, data).then((data: any) => {
    //  //console.log(data.length)
    //   this.server.managementsearcheventEmit.emit(data);
    // }).catch();
    this.searchOutput.emit(data)
  }
  //响应搜索
  changesearch() {
    this.search();
  }

}
